package model;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class Segment extends JPanel {

	private int x;
	private int y;
	private int segmentSize;
	private Color color;

	public Segment(int x, int y, int segmentSize) {
		this.x = x;
		this.y = y;
		this.segmentSize = segmentSize;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getSegmentSize() {
		return this.segmentSize;
	}

	public void setSegmentSize(int s) {
		this.segmentSize = s;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	/**
	 * bla, eriks jobs
	 */
	public boolean equals(Object seg) {
		return (this.x == ((Segment) seg).getX() && this.y == ((Segment) seg)
				.getY());
	}

	// newHead = oldHead.add(1,0)
	public Segment add(int[] direction) {
		int x = direction[0];
		int y = direction[1];
		Segment tmp = new Segment(this.x + x, this.y + y, this.segmentSize);
		tmp.setColor(this.color);
		return tmp;
	}

	@Override
	public void paint(Graphics g) {
		g.setColor(this.color);
		g.fillRect(this.x * this.segmentSize, this.y * this.segmentSize,
				this.segmentSize, this.segmentSize);
	}

}
